package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.corona.Game;
import com.esotericsoftware.kryonet.Server;
import com.corona.game.util.LinkedMusic;
import com.corona.game.util.StackTraces;
import com.corona.game.util.TextField;
import com.corona.game.util.TextureCache;
import com.corona.game.util.audio.AudioLoader;
import java.awt.Component;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/* compiled from: Action.java */
/* access modifiers changed from: package-private */
/* loaded from: pokewilds.jar:com/pkmngen/game/DrawSetupMenu.class */
public class DrawSetupMenu extends Action {
    public static boolean drawChoosePokemonText = true;
    public static int avatarAnimCounter = 24;
    public static int currIndex = 0;
    public static int lastIndex = 0;
    Sprite bgSprite;
    Sprite helperSprite;
    Vector2 newPos;
    public Action.Layer layer = Action.Layer.gui_5000;
    ArrayList<Sprite> avatarSprites = new ArrayList<>();
    int avatarColorIndex = 0;
    int playerColorIndex = 0;
    int playerTypeIndex = 0;
    ArrayList<String> playerTypes = new ArrayList<>();
    int localHostJoinIndex = 0;
    int newLoadIndex = 0;
    int sizeIndex = 0;
    int fileIndex = 0;
    int shinyRateIndex = 0;
    int shinyRatePow = 8;
    int offset = 0;
    int offset2 = 0;
    int offset3 = 0;
    ArrayList<Character> name = new ArrayList<>(11);
    ArrayList<Character> mapName = new ArrayList<>(11);
    ArrayList<Character> serverIp = new ArrayList<>();
    HashMap<Integer, Character> numberKeys = new HashMap<>();
    ArrayList<Color> colors = new ArrayList<>();
    ArrayList<String> fileNames = new ArrayList<>();
    private TextFieldSelected fieldSelected = TextFieldSelected.NONE;
    Sprite arrowWhite = new Sprite(TextureCache.get(Gdx.files.internal("battle/arrow_right_white.png")), 0, 0, 5, 7);
    Sprite arrow = new Sprite(TextureCache.get(Gdx.files.internal("battle/arrow_right1.png")), 0, 0, 5, 7);
    Sprite arrowFlipped = new Sprite(this.arrow);
    Sprite arrowDown = new Sprite(TextureCache.get(Gdx.files.internal("arrow_down.png")), 0, 0, 7, 5);
    Sprite arrowDownFlipped = new Sprite(this.arrowDown);
    Sprite selectColorBox = new Sprite(TextureCache.get(Gdx.files.internal("select_color1.png")), 0, 0, 16, 16);
    Map<Integer, Vector2> arrowCoords = new HashMap();

    /* compiled from: Action.java */
    /* loaded from: pokewilds.jar:com/pkmngen/game/DrawSetupMenu$TextFieldSelected.class */
    public enum TextFieldSelected {
        NONE,
        MAP_NAME,
        NAME
    }

    public DrawSetupMenu(Game game, Action nextAction) {
        super(game, nextAction);
        this.playerTypes.add("leaf");
        this.playerTypes.add("gold");
        this.playerTypes.add("kris");
        this.playerTypes.add("brendan");
        this.playerTypes.add("may");
        this.playerTypes.add("hilbert");
        this.playerTypes.add("hilda");
        this.playerTypes.add("rosa");
        this.playerTypes.add("calem");
        this.playerTypes.add("serena");
        this.playerTypes.add("chase");
        this.playerTypes.add("elaine");
        this.playerTypes.add("gloria");
        this.playerTypes.add("mark");
        this.playerTypes.add("mint");
        this.playerTypes.add("lunick");
        this.playerTypes.add("summer");
        this.playerTypes.add("kellyn");
        this.nextAction = nextAction;
        this.arrowFlipped.flip(true, false);
        this.avatarSprites.add(game.player.standingSprites.get("down"));
        this.avatarSprites.add(game.player.movingSprites.get("down"));
        this.avatarSprites.add(game.player.altMovingSprites.get("down"));
        currIndex = lastIndex;
        this.arrowDownFlipped.flip(false, true);
        for (int i = 0; i < 8; i++) {
            this.arrowCoords.put(Integer.valueOf(i), new Vector2(1.0f, (float) (128 - (16 * i))));
        }
        this.newPos = this.arrowCoords.get(Integer.valueOf(currIndex));
        this.bgSprite = new Sprite(TextureCache.get(Gdx.files.internal("battle/battle_bg3.png")), 0, 0, 176, 160);
        this.bgSprite.setPosition(-8.0f, -8.0f);
        char[] textArray = "1234567890".toCharArray();
        for (int i2 = 0; i2 < textArray.length; i2++) {
            this.numberKeys.put(Integer.valueOf(Input.Keys.valueOf(String.valueOf(textArray[i2]))), Character.valueOf(textArray[i2]));
        }
        this.numberKeys.put(56, '.');
        this.colors.add(new Color(0.972549f, 0.21960784f, 0.03137255f, 1.0f));
        this.colors.add(new Color(0.9411765f, 0.3137255f, 0.1882353f, 1.0f));
        this.colors.add(new Color(0.3137255f, 0.28235295f, 0.972549f, 1.0f));
        this.colors.add(Color.CYAN);
        this.colors.add(new Color(0.21960784f, 0.72156864f, 0.09411765f, 1.0f));
        this.colors.add(Color.MAGENTA);
        this.colors.add(Color.MAROON);
        this.colors.add(Color.YELLOW);
        this.colors.add(new Color(0.47058824f, 0.3137255f, 0.09411765f, 1.0f));
        this.colors.add(Color.OLIVE);
        this.colors.add(Color.TEAL);
        this.colors.add(Color.RED);
        this.colors.add(Color.PURPLE);
        this.colors.add(new Color(1.0f, 0.4509804f, 0.78431374f, 1.0f));
        for (FileHandle file : Gdx.files.local("").list()) {
            String filename = file.name();
            if (filename.endsWith(".sav")) {
                this.fileNames.add(filename);
            }
        }
        FileHandle[] files = Gdx.files.local("mods/player/").list();
        for (FileHandle file2 : files) {
            if (file2.isDirectory()) {
                String filename2 = file2.name();
                if (!this.playerTypes.contains(filename2)) {
                    this.playerTypes.add(filename2);
                    System.out.println("Found mods for: " + filename2);
                }
            }
        }
    }

    @Override // com.corona.game.Action
    public String getCamera() {
        return "gui";
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        if (Game.musicDisabled) {
            game.currMusic = AudioLoader.loadMusic("music/silence1.ogg");
            game.currMusic.setVolume(0.8f);
        } else {
            game.currMusic = new LinkedMusic("music/follow_me1_intro", "music/follow_me1");
            game.currMusic.setVolume(0.8f);
        }
        game.currMusic.play();
        game.player.setColor(this.colors.get(this.avatarColorIndex));
        Gdx.input.setInputProcessor(new InputAdapter() { // from class: com.corona.game.DrawSetupMenu.1
            @Override // com.badlogic.gdx.InputAdapter, com.badlogic.gdx.InputProcessor
            public boolean keyTyped(char character) {
                switch (AnonymousClass3.$SwitchMap$com$pkmngen$game$DrawSetupMenu$TextFieldSelected[DrawSetupMenu.this.fieldSelected.ordinal()]) {
                    case 1:
                        return DrawSetupMenu.this.updateField(character, DrawSetupMenu.this.name);
                    case 2:
                        return DrawSetupMenu.this.updateField(character, DrawSetupMenu.this.mapName);
                    default:
                        return false;
                }
            }
        });
    }

    /* compiled from: Action.java */
    /* renamed from: com.corona.game.DrawSetupMenu$3 */
    /* loaded from: pokewilds.jar:com/pkmngen/game/DrawSetupMenu$3.class */
    static /* synthetic */ class AnonymousClass3 {
        static final /* synthetic */ int[] $SwitchMap$com$pkmngen$game$DrawSetupMenu$TextFieldSelected = new int[TextFieldSelected.values().length];

        static {
            try {
                $SwitchMap$com$pkmngen$game$DrawSetupMenu$TextFieldSelected[TextFieldSelected.NAME.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                $SwitchMap$com$pkmngen$game$DrawSetupMenu$TextFieldSelected[TextFieldSelected.MAP_NAME.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
        }
    }

    public boolean updateField(char character, ArrayList<Character> characters) {
        return TextField.updateField(character, characters, 11, false);
    }

    @Override // com.corona.game.Action
    public void step(final Game game) {
        Sprite avatarSprite;
        int offsetX;
        this.newPos = this.arrowCoords.get(Integer.valueOf(currIndex));
        this.fieldSelected = TextFieldSelected.NONE;
        for (int j = 0; j < 8; j++) {
            if (j == 0) {
                char[] textArray = "LOCAL  ".toCharArray();
                for (int i = 0; i < textArray.length; i++) {
                    game.uiBatch.draw(game.textDict.get(Character.valueOf(textArray[i])), (float) (8 + (8 * i)), (float) (128 - (16 * j)));
                }
                int offsetX2 = 0;
                this.offset = 0;
                if (this.localHostJoinIndex == 1) {
                    offsetX2 = 56;
                }
                if (this.localHostJoinIndex == 2) {
                    offsetX2 = 112;
                    this.offset = -1;
                    this.offset2 = 0;
                    this.newLoadIndex = 0;
                }
                if (this.localHostJoinIndex == 1 && this.newLoadIndex == 0) {
                    this.offset3 = -2;
                } else {
                    this.offset3 = 0;
                }
                if (j == currIndex) {
                    this.newPos = this.newPos.cpy().add((float) offsetX2, 0.0f);
                }
                game.uiBatch.draw(this.arrowWhite, this.arrowCoords.get(Integer.valueOf(j)).x + ((float) offsetX2), this.arrowCoords.get(Integer.valueOf(j)).y);
            } else if (j == 1 + this.offset) {
                char[] textArray2 = "NEW    LOAD".toCharArray();
                for (int i2 = 0; i2 < textArray2.length; i2++) {
                    game.uiBatch.draw(game.textDict.get(Character.valueOf(textArray2[i2])), (float) (8 + (8 * i2)), (float) (128 - (16 * j)));
                }
                int offsetX3 = 0;
                if (this.newLoadIndex == 1) {
                    offsetX3 = 56;
                    this.offset2 = -3;
                } else {
                    this.offset2 = 0;
                }
                if (j == currIndex) {
                    if (InputProcessor.leftJustPressed && this.newLoadIndex > 0) {
                        this.newLoadIndex--;
                    }
                    if (InputProcessor.rightJustPressed && this.newLoadIndex < 1) {
                        this.newLoadIndex++;
                    }
                    this.newPos = this.newPos.cpy().add((float) offsetX3, 0.0f);
                }
                game.uiBatch.draw(this.arrowWhite, this.arrowCoords.get(Integer.valueOf(j)).x + ((float) offsetX3), this.arrowCoords.get(Integer.valueOf(j)).y);
            } else if (j == 2 + this.offset + this.offset2) {
                if (this.localHostJoinIndex == 2) {
                    char[] textArray3 = "Server IP".toCharArray();
                    for (int i3 = 0; i3 < textArray3.length; i3++) {
                        game.uiBatch.draw(game.textDict.get(Character.valueOf(textArray3[i3])), (float) (8 + (8 * i3)), (float) (128 - (16 * j)));
                    }
                    for (int i4 = 0; i4 < this.serverIp.size(); i4++) {
                        game.uiBatch.draw(game.textDict.get(this.serverIp.get(i4)), (float) (8 + (8 * i4)), (float) (128 - (16 * (j + 1))));
                    }
                    if (j == currIndex + this.offset) {
                        if (this.serverIp.size() < 15) {
                            for (Integer key : this.numberKeys.keySet()) {
                                if (Gdx.input.isKeyJustPressed(key.intValue())) {
                                    this.serverIp.add(this.numberKeys.get(key));
                                }
                            }
                        }
                        if (Gdx.input.isKeyJustPressed(67) && this.serverIp.size() > 0) {
                            this.serverIp.remove(this.serverIp.size() - 1);
                        }
                        if (avatarAnimCounter >= 12) {
                            game.uiBatch.draw(game.textDict.get('_'), (float) (8 + (8 * this.serverIp.size())), (float) (112 - (16 * j)));
                        }
                    } else if (this.serverIp.size() <= 0) {
                        char[] textArray4 = "127.0.0.1".toCharArray();
                        for (int i5 = 0; i5 < textArray4.length; i5++) {
                            game.uiBatch.draw(game.textDict.get(Character.valueOf(textArray4[i5])), (float) (8 + (8 * i5)), (float) (128 - (16 * (j + 1))));
                        }
                    }
                } else {
                    char[] textArray5 = "File".toCharArray();
                    for (int i6 = 0; i6 < textArray5.length; i6++) {
                        game.uiBatch.draw(game.textDict.get(Character.valueOf(textArray5[i6])), (float) (8 + (8 * i6)), (float) (128 - (16 * j)));
                    }
                    if (j == currIndex + this.offset) {
                        this.fieldSelected = TextFieldSelected.MAP_NAME;
                        if (avatarAnimCounter >= 12) {
                            game.uiBatch.draw(game.textDict.get('_'), (float) (48 + (8 * this.mapName.size())), (float) (128 - (16 * j)));
                        }
                    } else if (this.mapName.size() <= 0) {
                        char[] textArray6 = "default".toCharArray();
                        for (int i7 = 0; i7 < textArray6.length; i7++) {
                            game.uiBatch.draw(game.textDict.get(Character.valueOf(textArray6[i7])), (float) (48 + (8 * i7)), (float) (128 - (16 * j)));
                        }
                    }
                    for (int i8 = 0; i8 < this.mapName.size(); i8++) {
                        game.uiBatch.draw(game.textDict.get(this.mapName.get(i8)), (float) (48 + (8 * i8)), (float) (128 - (16 * j)));
                    }
                }
            } else if (j == 3 + this.offset + this.offset2 && this.localHostJoinIndex != 2) {
                char[] textArray7 = "World S M L XL XXL".toCharArray();
                for (int i9 = 0; i9 < textArray7.length; i9++) {
                    game.uiBatch.draw(game.textDict.get(Character.valueOf(textArray7[i9])), (float) (8 + (8 * i9)), (float) (128 - (16 * j)));
                }
                if (this.sizeIndex == 0) {
                    offsetX = 0;
                } else if (this.sizeIndex < 5) {
                    offsetX = 32 + (16 * this.sizeIndex);
                } else {
                    offsetX = 40 + (16 * this.sizeIndex);
                }
                if (j == currIndex + this.offset) {
                    if (InputProcessor.leftJustPressed && this.sizeIndex > 0) {
                        this.sizeIndex--;
                    }
                    if (InputProcessor.rightJustPressed && this.sizeIndex < 5) {
                        this.sizeIndex++;
                    }
                    this.newPos = this.newPos.cpy().add((float) offsetX, 0.0f);
                }
                game.uiBatch.draw(this.arrowWhite, this.arrowCoords.get(Integer.valueOf(j)).x + ((float) offsetX), this.arrowCoords.get(Integer.valueOf(j)).y);
            } else if (j == 4 + this.offset + this.offset2 + this.offset3) {
                char[] textArray8 = "Name".toCharArray();
                for (int i10 = 0; i10 < textArray8.length; i10++) {
                    game.uiBatch.draw(game.textDict.get(Character.valueOf(textArray8[i10])), (float) (8 + (8 * i10)), (float) (128 - (16 * j)));
                }
                if (j == currIndex) {
                    this.fieldSelected = TextFieldSelected.NAME;
                    if (avatarAnimCounter >= 12) {
                        game.uiBatch.draw(game.textDict.get('_'), (float) (48 + (8 * this.name.size())), (float) (128 - (16 * j)));
                    }
                }
                for (int i11 = 0; i11 < this.name.size(); i11++) {
                    game.uiBatch.draw(game.textDict.get(this.name.get(i11)), (float) (48 + (8 * i11)), (float) (128 - (16 * j)));
                }
            } else if (j == 5 + this.offset + this.offset2 + this.offset3 && this.newLoadIndex != 1) {
                if (j == currIndex) {
                    if (avatarAnimCounter >= 18) {
                        avatarSprite = new Sprite(this.avatarSprites.get(0));
                    } else if (avatarAnimCounter >= 12) {
                        avatarSprite = new Sprite(this.avatarSprites.get(1));
                    } else if (avatarAnimCounter >= 6) {
                        avatarSprite = new Sprite(this.avatarSprites.get(0));
                    } else {
                        avatarSprite = new Sprite(this.avatarSprites.get(2));
                    }
                    if (InputProcessor.leftJustPressed) {
                        this.playerColorIndex--;
                        if (this.playerColorIndex < 0) {
                            this.playerColorIndex = 0;
                        }
                    } else if (InputProcessor.downJustPressed) {
                        if (this.playerColorIndex == 1) {
                            this.avatarColorIndex--;
                            if (this.avatarColorIndex < 0) {
                                this.avatarColorIndex = this.colors.size() - 1;
                            }
                            game.player.setColor(this.colors.get(this.avatarColorIndex));
                            this.avatarSprites.clear();
                            this.avatarSprites.add(game.player.standingSprites.get("down"));
                            this.avatarSprites.add(game.player.movingSprites.get("down"));
                            this.avatarSprites.add(game.player.altMovingSprites.get("down"));
                        } else if (this.playerColorIndex == 2) {
                            this.playerTypeIndex--;
                            if (this.playerTypeIndex < 0) {
                                this.playerTypeIndex = this.playerTypes.size() - 1;
                            }
                            String name = "";
                            for (int i12 = 0; i12 < this.name.size(); i12++) {
                                name = name + this.name.get(i12).toString();
                            }
                            if (name.equals("") || name.equalsIgnoreCase(game.player.character)) {
                                this.name.clear();
                                String newName = this.playerTypes.get(this.playerTypeIndex).toUpperCase(Locale.ROOT);
                                for (int i13 = 0; i13 < newName.length(); i13++) {
                                    this.name.add(Character.valueOf(newName.charAt(i13)));
                                }
                            }
                            game.player.character = this.playerTypes.get(this.playerTypeIndex);
                            game.player.setColor(this.colors.get(this.avatarColorIndex));
                            this.avatarSprites.clear();
                            this.avatarSprites.add(game.player.standingSprites.get("down"));
                            this.avatarSprites.add(game.player.movingSprites.get("down"));
                            this.avatarSprites.add(game.player.altMovingSprites.get("down"));
                        }
                    } else if (InputProcessor.rightJustPressed) {
                        this.playerColorIndex++;
                        if (this.playerColorIndex > 2) {
                            this.playerColorIndex = 2;
                        }
                    } else if (InputProcessor.upJustPressed) {
                        if (this.playerColorIndex == 1) {
                            this.avatarColorIndex++;
                            if (this.avatarColorIndex >= this.colors.size()) {
                                this.avatarColorIndex = 0;
                            }
                            game.player.setColor(this.colors.get(this.avatarColorIndex));
                            this.avatarSprites.clear();
                            this.avatarSprites.add(game.player.standingSprites.get("down"));
                            this.avatarSprites.add(game.player.movingSprites.get("down"));
                            this.avatarSprites.add(game.player.altMovingSprites.get("down"));
                        } else if (this.playerColorIndex == 2) {
                            this.playerTypeIndex++;
                            if (this.playerTypeIndex >= this.playerTypes.size()) {
                                this.playerTypeIndex = 0;
                            }
                            String name2 = "";
                            for (int i14 = 0; i14 < this.name.size(); i14++) {
                                name2 = name2 + this.name.get(i14).toString();
                            }
                            if (name2.equals("") || name2.equalsIgnoreCase(game.player.character)) {
                                this.name.clear();
                                String newName2 = this.playerTypes.get(this.playerTypeIndex).toUpperCase(Locale.ROOT);
                                for (int i15 = 0; i15 < newName2.length(); i15++) {
                                    this.name.add(Character.valueOf(newName2.charAt(i15)));
                                }
                            }
                            game.player.character = this.playerTypes.get(this.playerTypeIndex);
                            game.player.setColor(this.colors.get(this.avatarColorIndex));
                            this.avatarSprites.clear();
                            this.avatarSprites.add(game.player.standingSprites.get("down"));
                            this.avatarSprites.add(game.player.movingSprites.get("down"));
                            this.avatarSprites.add(game.player.altMovingSprites.get("down"));
                        }
                    }
                } else {
                    avatarSprite = new Sprite(this.avatarSprites.get(0));
                }
                if (this.playerColorIndex == 1) {
                    game.uiBatch.draw(this.arrowDown, 58.0f, (float) (124 - (16 * j)));
                    game.uiBatch.draw(this.arrowDownFlipped, 58.0f, (float) (132 - (16 * j)));
                    this.newPos = this.newPos.cpy().add((float) (16 + (32 * this.playerColorIndex)), 0.0f);
                }
                if (this.playerColorIndex == 2) {
                    game.uiBatch.draw(this.arrowDown, 88.0f, (float) (124 - (16 * j)));
                    game.uiBatch.draw(this.arrowDownFlipped, 88.0f, (float) (132 - (16 * j)));
                    this.newPos = this.newPos.cpy().add((float) (16 + (32 * this.playerColorIndex)), 0.0f);
                }
                this.selectColorBox.setColor(this.colors.get(this.avatarColorIndex));
                this.selectColorBox.setPosition(66.0f, (float) (123 - (16 * j)));
                this.selectColorBox.draw(game.uiBatch);
                game.uiBatch.draw(avatarSprite, 96.0f, (float) (124 - (16 * j)));
                char[] textArray9 = "Player".toCharArray();
                for (int i16 = 0; i16 < textArray9.length; i16++) {
                    game.uiBatch.draw(game.textDict.get(Character.valueOf(textArray9[i16])), (float) (8 + (8 * i16)), (float) (128 - (16 * (j + this.offset))));
                }
            } else if (j == 5 + this.offset + this.offset2 + this.offset3) {
                if (!this.fileNames.isEmpty()) {
                    char[] textArray10 = this.fileNames.get(this.fileIndex).toCharArray();
                    for (int i17 = 0; i17 < textArray10.length; i17++) {
                        game.uiBatch.draw(game.textDict.get(Character.valueOf(textArray10[i17])), (float) (32 + (8 * i17)), (float) (124 - (16 * (j + this.offset))));
                    }
                    game.uiBatch.draw(this.arrowFlipped, 16.0f, (float) (124 - (16 * (j + this.offset))));
                    game.uiBatch.draw(this.arrow, (float) (43 + (8 * this.fileNames.get(this.fileIndex).length())), (float) (124 - (16 * j)));
                }
                if (j == currIndex) {
                    if (InputProcessor.leftJustPressed) {
                        this.fileIndex--;
                        if (this.fileIndex < 0) {
                            this.fileIndex = this.fileNames.size() - 1;
                        }
                    }
                    if (InputProcessor.rightJustPressed) {
                        this.fileIndex++;
                        if (this.fileIndex > this.fileNames.size() - 1) {
                            this.fileIndex = 0;
                        }
                    }
                }
            } else if (j == 6 + this.offset + this.offset2 + this.offset3) {
                char[] textArray11 = "Go!".toCharArray();
                for (int i18 = 0; i18 < textArray11.length; i18++) {
                    game.uiBatch.draw(game.textDict.get(Character.valueOf(textArray11[i18])), (float) (8 + (8 * i18)), (float) (128 - (16 * j)));
                }
                if (j == currIndex && (InputProcessor.startJustPressed || InputProcessor.aJustPressed)) {
                    Gdx.input.setInputProcessor(null);
                    String mapName = "";
                    if (this.newLoadIndex == 0) {
                        for (int i19 = 0; i19 < this.mapName.size(); i19++) {
                            mapName = mapName + this.mapName.get(i19).toString();
                        }
                        if (mapName.equals("")) {
                            mapName = "default";
                        }
                    } else {
                        mapName = this.fileNames.get(this.fileIndex).split("\\.sav")[0];
                    }
                    if (game.debugInputEnabled || this.newLoadIndex != 0 || !this.fileNames.contains(mapName + ".sav") || JOptionPane.showConfirmDialog((Component) null, "A save file with the same name already exists - overwrite?", "WARNING", 0) != 1) {
                        game.insertAction(new FadeMusic(game.currMusic, -0.0125f, new CallMethod(game.currMusic, "stop", new Object[0], new CallMethod(game.currMusic, "dispose", new Object[0], null))));
                        if (this.localHostJoinIndex != 2) {
                            final Action hostAction = null;
                            if (this.localHostJoinIndex == 1) {
                                try {
                                    game.initServer();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                game.insertAction(new ServerBroadcast(game));
                                game.debugInputEnabled = true;
                                hostAction = new DisplayText(game, "Welcome to host mode!           WASD moves camera     Q and E zooms", (String) null, (Action) null, (Action) null);
                            } else {
                                game.server = new Server();
                                Network.register(game.server);
                            }
                            final Action drawControls = new DrawControls();
                            game.map = new PkmnMap(mapName);
                            if (this.newLoadIndex == 0) {
                                game.actionStack.remove(this);
                                if (this.sizeIndex == 0) {
                                    if (!game.debugInputEnabled) {
                                        this.sizeIndex = 1;
                                    } else {
                                        this.sizeIndex = -1;
                                    }
                                }
                                int something = 100;
                                if (this.sizeIndex > 4) {
                                    something = 80;
                                } else if (this.sizeIndex > 3) {
                                    something = 90;
                                }
                                final int size = 100 * something * (this.sizeIndex + 2);
                                Thread thread = new Thread(new Runnable() { // from class: com.corona.game.DrawSetupMenu.2
                                    @Override // java.lang.Runnable
                                    public void run() {
                                        try {
                                            System.out.println("Generating map...");
                                            System.out.println(LocalTime.now());
                                            final Action genIsland = new GenIsland1(Game.staticGame, new Vector2(0.0f, 0.0f), size);
                                            System.out.println("Done.");
                                            System.out.println(LocalTime.now());
                                            Thread.sleep(4000);
                                            Gdx.app.postRunnable(new Runnable() { // from class: com.corona.game.DrawSetupMenu.2.1
                                                @Override // java.lang.Runnable
                                                public void run() {
                                                    Game.staticGame.start();
                                                    Game.staticGame.insertAction(genIsland);
                                                    genIsland.step(Game.staticGame);
                                                    EnterBuilding enterBuilding = new EnterBuilding(Game.staticGame, "", null);
                                                    enterBuilding.slow = 8;
                                                    Game.staticGame.insertAction(enterBuilding);
                                                    Game.staticGame.insertAction(new DisplayText.Clear(Game.staticGame, new SetField(drawControls, "remove", true, hostAction)));
                                                    Game.staticGame.map.minimap = new Pixmap(((int) (Game.staticGame.map.topRight.x - Game.staticGame.map.bottomLeft.x)) / 8, ((int) (Game.staticGame.map.topRight.y - Game.staticGame.map.bottomLeft.y)) / 8, Pixmap.Format.RGBA8888);
                                                    Game.staticGame.map.minimap.setColor(0.0f, 0.0f, 0.0f, 1.0f);
                                                    Game.staticGame.map.minimap.fill();
                                                    Vector2 startPos = game.player.position.cpy().add(-128.0f, -128.0f);
                                                    startPos.x = (float) (((int) startPos.x) - (((int) startPos.x) % 16));
                                                    startPos.y = (float) (((int) startPos.y) - (((int) startPos.y) % 16));
                                                    Vector2 endPos = game.player.position.cpy().add(128.0f, 128.0f);
                                                    endPos.x = (float) (((int) endPos.x) - (((int) endPos.x) % 16));
                                                    endPos.y = (float) (((int) endPos.y) - (((int) endPos.y) % 16));
                                                    Vector2 currPos = new Vector2(startPos.x, startPos.y);
                                                    while (currPos.y < endPos.y) {
                                                        Tile tile = Game.staticGame.map.tiles.get(currPos);
                                                        currPos.x += 16.0f;
                                                        if (currPos.x > endPos.x) {
                                                            currPos.x = startPos.x;
                                                            currPos.y += 16.0f;
                                                        }
                                                        if (tile != null) {
                                                            tile.updateMiniMap(game);
                                                        }
                                                    }
                                                }
                                            });
                                        } catch (Exception e2) {
                                            e2.printStackTrace();
                                        }
                                    }
                                });
                                thread.setPriority(1);
                                thread.start();
                                game.insertAction(new DisplayText(game, "Generating... please wait...", (String) null, true, false, (Action) null));
                                game.insertAction(drawControls);
                                String name3 = "";
                                for (int i20 = 0; i20 < this.name.size(); i20++) {
                                    name3 = name3 + this.name.get(i20).toString();
                                }
                                game.player.name = name3;
                            } else {
                                game.actionStack.remove(this);
                                game.start();
                                try {
                                    game.map.loadFromFile(game);
                                    InputProcessor.aJustPressed = false;
                                } catch (Exception e2) {
                                    e2.printStackTrace();
                                    JFrame frame = new JFrame("Error");
                                    StringWriter traceback = new StringWriter();
                                    StackTraces.writeStackTrace(e2, new PrintWriter(traceback));
                                    JOptionPane.showMessageDialog(frame, "There was an error loading this file:\n\n" + traceback.toString());
                                    System.exit(0);
                                }
                                EnterBuilding enterBuilding = new EnterBuilding(game, "", null);
                                enterBuilding.slow = 8;
                                game.insertAction(enterBuilding);
                                if (game.debugInputEnabled) {
                                    game.insertAction(new TileEditor());
                                }
                            }
                        } else {
                            String name4 = "";
                            for (int i21 = 0; i21 < this.name.size(); i21++) {
                                name4 = name4 + this.name.get(i21).toString();
                            }
                            game.player.name = name4;
                            String ipAddr = "";
                            for (int i22 = 0; i22 < this.serverIp.size(); i22++) {
                                ipAddr = ipAddr + this.serverIp.get(i22).toString();
                            }
                            if (ipAddr.equals("")) {
                                ipAddr = "127.0.0.1";
                            }
                            game.actionStack.remove(this);
                            game.map = new PkmnMap("default");
                            game.start();
                            try {
                                game.initClient(ipAddr);
                            } catch (IOException e3) {
                                e3.printStackTrace();
                            }
                            EnterBuilding enterBuilding2 = new EnterBuilding(game, "", null);
                            enterBuilding2.slow = 8;
                            game.insertAction(enterBuilding2);
                        }
                    } else {
                        return;
                    }
                }
            } else {
                continue;
            }
        }
        avatarAnimCounter--;
        if (avatarAnimCounter <= 0) {
            avatarAnimCounter = 24;
        }
        int max = 6;
        if (this.localHostJoinIndex == 2) {
            max = 5;
        }
        if (this.localHostJoinIndex == 1) {
            max = 4;
        }
        if (this.newLoadIndex == 1) {
            max = 3;
        }
        if (this.playerColorIndex == 0) {
            if (InputProcessor.upJustPressed) {
                if (currIndex > 0) {
                    currIndex--;
                    if (this.localHostJoinIndex == 2 && currIndex == 1) {
                        currIndex--;
                    }
                    avatarAnimCounter = 24;
                } else {
                    currIndex = max;
                }
            } else if (InputProcessor.downJustPressed) {
                if (currIndex < max) {
                    currIndex++;
                    if (this.localHostJoinIndex == 2 && currIndex == 1) {
                        currIndex++;
                    }
                    avatarAnimCounter = 24;
                } else {
                    currIndex = 0;
                }
            }
            this.arrow.setPosition(this.newPos.x, this.newPos.y);
            this.arrow.draw(game.uiBatch);
        }
    }
}
